<template>
	<view style="height: 100%;">
		<view class="wrap">
			<view class="u-tabs-box">
				<!-- <u-tabs activeColor="#f29100" ref="tabs" :list="list" :current="current" @change="change" :is-scroll="false"
					swiperWidth="750"></u-tabs> -->
			</view>
			<swiper class="swiper-box" :current="swiperCurrent" @animationfinish="animationfinish">
				<swiper-item class="swiper-item" v-for="(orderlist, index) in orderList" :key="index">
					<scroll-view scroll-y style="height: 100%;width: 100%;padding-bottom: 50rpx; " v-if="orderlist.length !== 0">
						<view class="page-box">
							<view class="order" v-for="(res, index) in orderlist" :key="res.id">
								<view class="top">
									<view class="left">
										<u-icon name="order" :size="30" color="rgb(94,94,94)"></u-icon>
										<view class="store">{{ res.orderNo }}</view>
										<u-icon name="arrow-right" color="rgb(203,203,203)" :size="26"></u-icon>
									</view>
									<view class="right" style="color: gray;" v-if="res.status===0">初始化</view>
									<view class="right" style="color: coral;" v-if="res.status===1">待支付</view>
									<view class="right" style="color: green;" v-if="res.status===2">支付成功</view>
									<view class="right" style="color: red;" v-if="res.status===9">取消支付</view>
								</view>
								<view class="item">
									<!-- <view class="left">
										<image :src="item.goodsUrl" mode="aspectFill"></image>
									</view> -->
									<view class="content">
										<view class="title u-line-3">
											{{res.title}}
											<span class="number" style="color: lightgray">x{{res.total}}</span>
										</view>
										<view class="type">支付方式：{{ res.paymentWay }}</view>
										<view class="delivery-time">创建时间：{{ res.createTime }}</view>
									</view>
									<!-- <view class="right">
										<view class="price">
											￥{{ priceInt(item.price) }}
											<text class="decimal">.{{ priceDecimal(item.price) }}</text>
										</view>
										<view class="number">x{{ item.number }}</view>
									</view> -->
								</view>
								<view class="total">
									共1件商品 金额:
									<text class="total-price">
										￥{{ res.amount/100 }}
									</text>
								</view>
								<view class="bottom">
									<!--<view class="more"><u-icon name="more-dot-fill" color="rgb(203,203,203)"></u-icon>
									<view class="logistics btn">查看物流</view>
									<view class="exchange btn">卖了换钱</view>
									</view> -->

									<view class="evaluate btn" @click="confirmDialog(res)" v-if="res.status===1">是否到款，请确认</view>
								</view>
							</view>
						</view>
						<!-- <u-loadmore :status="loadStatus[0]" bgColor="#f2f2f2"></u-loadmore> -->
						<uni-load-more :status="loadStatus[0]"></uni-load-more>
					</scroll-view>
					<scroll-view scroll-y style="height: 100%;width: 100%;" v-else>
						<view class="page-box">
							<view class="centre">
								<view style="justify-content: center;display: flex;">
									<image src="https://cdn.uviewui.com/uview/template/taobao-order.png" mode=""></image>
								</view>
								<view class="explain">
									您还没有相关的订单
									<!-- <view class="tips">可以去看看有那些想买的</view> -->
								</view>
								<!-- <view class="btn">随便逛逛</view> -->
							</view>
						</view>
					</scroll-view>
				</swiper-item>
			</swiper>
			<view>
				<uni-popup ref="alertDialog" type="dialog">
					<uni-popup-dialog type="info" cancelText="取消" confirmText="确认" title="提醒" :content="alertContent" @confirm="payConfirm"
						@close="dialogClose"></uni-popup-dialog>
				</uni-popup>
			</view>
		</view>
	</view>	
</template>

<script>
import { list,confirm } from "@/api/seller/order"
export default {
	data() {
		return {
			orderList: [[]],
			list: [
				{name: '全部',count: 12}
			],
			total: 0,
			current: 0,
			swiperCurrent: 0,
			currentOrder: null,
			alertContent: "确定订单已收款?",
			loadStatus: ['more'],
			isLoadMore: false,
			params: {"pageSize":10,"pageNum":1}
		};
	},
	onLoad() {
		this.getOrderList();
	},
	// 上拉触底函数
	onReachBottom() {
		if (!this.isLoadMore) {
			this.isLoadMore = true
			this.params.pageNum = this.params.pageNum+1; //下拉一次页数+1
			this.getOrderList()
		}
	},
	//下拉刷新
	onPullDownRefresh() {
		//重新触发获取数据方法，刷新接口
		this.reservList = []	
		this.params.pageNum = 1//重置页码，每次刷新后页码均为第一页
		this.getOrderList()
		//结束刷新
		uni.stopPullDownRefresh()
	},
	methods: {
		confirmDialog(res) {
			this.currentOrder = res;
			this.alertContent = "订单("+res.orderNo+")已收款?";
			this.$refs.alertDialog.open()
		},
		// 页面数据
		getOrderList() {
			list(this.params).then(res=>{
				this.total = res.total
				if(this.params.pageNum==1){
					this.orderList[0] = res.rows
				}else{
					this.orderList[0] = this.orderList[0].concat(res.rows)
				}
				this.isLoadMore = false
				if(this.total<=(this.params.pageSize*this.params.pageNum)){
					this.loadStatus[0] = "noMore"
				}else{
					this.loadStatus[0] = "more"
				}
			})
		},

		//确认支付
		payConfirm() {
			confirm(this.currentOrder.id).then(res=>{
				uni.showToast({
				  title: '确认成功',
				  mask: false,
				  icon:"none",
				  duration: 3000
				});
				this.getOrderList();
			})
		},

		// tab栏切换
		change({ index }) {
			this.swiperCurrent = index;
			this.getOrderList(index);
		},
		animationfinish({ detail: { current } }) {
			this.swiperCurrent = current;
			this.current = current;
		}
	}
};
</script>

<style>
/* #ifndef H5 */
page {
	height: 100%;
	background-color: #f2f2f2;
}

/* #endif */
</style>

<style lang="scss" scoped>
.order {
	width: 710rpx;
	background-color: #ffffff;
	margin: 20rpx auto;
	border-radius: 20rpx;
	box-sizing: border-box;
	padding: 20rpx;
	font-size: 28rpx;

	.top {
		display: flex;
		justify-content: space-between;

		.left {
			display: flex;
			align-items: center;

			.store {
				margin: 0 10rpx;
				font-size: 32rpx;
				font-weight: bold;
			}
		}

		.right {
			color: $u-warning-dark;
		}
	}

	.item {
		display: flex;
		margin: 20rpx 0 0;

		.left {
			margin-right: 20rpx;

			image {
				width: 200rpx;
				height: 200rpx;
				border-radius: 10rpx;
			}
		}

		.content {
			.title {
				font-size: 28rpx;
				line-height: 50rpx;
			}

			.type {
				margin: 10rpx 0;
				font-size: 24rpx;
				color: blue;
			}

			.delivery-time {
				color: #e5d001;
				font-size: 24rpx;
			}
		}

		.right {
			margin-left: 10rpx;
			padding-top: 20rpx;
			text-align: right;

			.decimal {
				font-size: 24rpx;
				margin-top: 4rpx;
			}

			.number {
				color: $u-tips-color;
				font-size: 24rpx;
			}
		}
	}

	.total {
		margin-top: 20rpx;
		text-align: right;
		font-size: 24rpx;

		.total-price {
			font-size: 32rpx;
		}
	}

	.bottom {
		display: flex;
		margin-top: 5rpx;
		margin-left: 10rpx;
		justify-content: space-between;
		align-items: center;

		.btn {
			line-height: 52rpx;
			width: 260rpx;
			border-radius: 26rpx;
			border: 2rpx solid $u-border-color;
			font-size: 26rpx;
			text-align: center;
			color: $u-info-dark;
		}

		.evaluate {
			color: $u-warning-dark;
			border-color: $u-warning-dark;
		}
	}
}

.centre {
	text-align: center;
	margin: 200rpx auto;
	font-size: 32rpx;
	image {
		width: 164rpx;
		height: 164rpx;
		border-radius: 50%;
		margin-bottom: 20rpx;
	}

	.tips {
		font-size: 24rpx;
		color: #999999;
		margin-top: 20rpx;
	}

	.btn {
		margin: 80rpx auto;
		width: 200rpx;
		border-radius: 32rpx;
		line-height: 64rpx;
		color: #ffffff;
		font-size: 26rpx;
		background: linear-gradient(270deg, rgba(249, 116, 90, 1) 0%, rgba(255, 158, 1, 1) 100%);
	}
}

.wrap {
	display: flex;
	flex-direction: column;
	height: 2000rpx;
	width: 100%;
	box-sizing: border-box;
	overflow: scroll;
}

.swiper-box {
	flex: 1;
}

.swiper-item {
	height: 100%;
}
</style>
